import { observable, action } from "mobx";
import request from "../utils/request";
import * as api from "../api/api";
import { LoadHoc, loading } from '../hoc/loadHoc';

export default class DynamicStore extends LoadHoc {
  /**
   * 动态列表
   */
  @observable allDynamic: api.YNJWTDynamicVODynamicVO = {};

  @loading @action async getAllDynamic(params: {
    dynamicType: number,
    pageIndex: number,
    pageSize: number,
    callback?: (allDynamic: api.YNJWTDynamicVODynamicVO) => void;
  }) {
    const { dynamicType, pageIndex, pageSize, callback } = params;
    const allDynamic = await request(api.AppdynamicApiFetchParamCreactor.appdynamicGetAllDynamicAsync({
      formDynamicType: dynamicType,
      formSkipCount: (pageIndex-1)*pageSize,
      formMaxResultCount: pageSize
    }));
    this.allDynamic = allDynamic;
    callback&&callback(allDynamic);
  }

  /**
   * 动态详情
   *
   */
  @observable dynamicInfo: api.YNJWTDynamicVODynamicVO = {};

  @loading @action async getDynamicInfo(params: {
    id: number,
    callback?: (Dynamic: api.YNJWTDynamicVODynamicVO) => void;
  }) {
    const { id, callback } = params;
    const dynamicInfo = await request(api.AppdynamicApiFetchParamCreactor.appdynamicGetDynamicInfoAsync({
      formId: id
    }));
    this.dynamicInfo = dynamicInfo;
    callback&&callback(dynamicInfo);
  }

  /**
   * 动态分类
   * GET /api/services/app/dynamicType/GetAllDynamicType
   */
  @observable allDynamicType: api.YNJWTDynamicVODynamicTypeVO = {};

  @loading @action async getAllDynamicType(params: {
    keyWorlds?: string,
    callback?: (res: api.YNJWTDynamicVODynamicTypeVO) => void;
  }) {
    const { keyWorlds, callback } = params;
    const allDynamicType = await request(api.AppdynamicTypeApiFetchParamCreactor.appdynamicTypeGetAllDynamicTypeAsync({
      formKeyWorlds: keyWorlds
    }));
    this.allDynamicType = allDynamicType;
    callback&&callback(allDynamicType);
  }
}
